package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.ReplyHistory;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/28
 */

public class ReplyReportListAdapter extends RecyclerAdapter<ReplyHistory, ReplyReportListAdapter.ReplyReportViewHolder> {
    private int status;

    public ReplyReportListAdapter(Context context, List<ReplyHistory> dataList) {
        super(context, dataList);
    }

    public void setStatus(int status) {
        this.status = status;
    }

    @Override
    public ReplyReportViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_reply_report_list_enterprise, null);
        return new ReplyReportViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ReplyReportViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class ReplyReportViewHolder extends RecyclerAdapter.BaseViewHolder<ReplyHistory>{
        @BindView(R.id.top_view)
        View topView;
        @BindView(R.id.bottom_view)
        View bottomView;
        @BindView(R.id.left_view)
        View leftView;
        @BindView(R.id.center_img)
        ImageView centerImg;
        @BindView(R.id.status_tv)
        HXTextView statusTv;
        @BindView(R.id.right_icon)
        ImageView rightIcon;
        @BindView(R.id.content_tv)
        HXTextView contentTv;
        @BindView(R.id.name_tv)
        HXTextView nameTv;
        @BindView(R.id.time_tv)
        HXTextView timeTv;
        @BindView(R.id.pic_rv)
        RecyclerView picRv;

        ReplyReportListPicAdapter picAdapter;

        public ReplyReportViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            ReplyHistory replyHistory = dataList.get(position);
            contentTv.setText("回复内容：" + replyHistory.getRemark());
            List<String> picList = replyHistory.getPicList();
            if(picList != null &&picList.size() > 0){
                picAdapter = new ReplyReportListPicAdapter(context, picList);
                picRv.setAdapter(picAdapter);
                picRv.setItemAnimator(new DefaultItemAnimator());
                picRv.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
            }
            timeTv.setText(replyHistory.getCreateTime());
            if(status == replyHistory.getCorrectiveStatus()){
                centerImg.setImageResource(R.mipmap.icon_blue_point);
            }else {
                centerImg.setImageResource(R.drawable.grey_point_r8dp);
            }
            switch (replyHistory.getCorrectiveStatus()){//状态 1待回复 2待复检 3不通过 4已完成
                case 1:
                    statusTv.setText("任务下发");
                    statusTv.setTextColor(context.getResources().getColor(R.color.color_999999));
                    nameTv.setText("派发人：" + replyHistory.getCreateBy());
                    bottomView.setVisibility(View.GONE);
                    leftView.setVisibility(View.GONE);
                    rightIcon.setVisibility(View.GONE);
                    break;
                case 2:
                    statusTv.setText("提交复检");
                    statusTv.setTextColor(context.getResources().getColor(R.color.color_999999));
                    nameTv.setText("派发人：" + replyHistory.getCreateBy());
                    rightIcon.setVisibility(View.GONE);
                    break;
                case 3:
                    statusTv.setText("复检不通过");
                    statusTv.setTextColor(context.getResources().getColor(R.color.color_F5573F));
                    nameTv.setText("派发人：" + replyHistory.getCreateBy());
                    rightIcon.setImageResource(R.mipmap.canceled);
                    rightIcon.setVisibility(View.VISIBLE);
                    break;
                case 4:
                    statusTv.setText("完成");
                    statusTv.setTextColor(context.getResources().getColor(R.color.color_999999));
                    nameTv.setText("派发人：" + replyHistory.getCreateBy());
                    topView.setVisibility(View.GONE);
                    rightIcon.setVisibility(View.GONE);
                    break;
            }
        }
    }
}
